import Vue from 'vue'
import App from '@/App'
import router from '@/router'                 // api: https://github.com/vuejs/vue-router
import store from '@/store'                   // api: https://github.com/vuejs/vuex
import i18n from './lang'                     // internationalization
import VueCookie from 'vue-cookie'            // api: https://github.com/alfhen/vue-cookie
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '@/icons'                              // api: http://www.iconfont.cn/
import '@/assets/scss/index.scss'
import httpRequest from '@/utils/httpRequest' // api: https://github.com/axios/axios
import { isAuth } from '@/utils'
import moment from 'moment'
import Print from '@/utils/print'
import { formatMoney, absNumber } from '@/utils/common'



// 适配flex
import '@/utils/flexible.js'

// 注册为全局
Vue.use(Print)
Vue.use(VueCookie)
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value)
})
Vue.config.productionTip = false

// 注册金额全局过滤器
Vue.filter('formatMoney', formatMoney)
Vue.filter('absNumber', absNumber)

// 时间格式转换:为空时不显示时间
// <template slot-scope="scope">{{ scope.row.publishTime | dateformat('YYYY-MM-DD HH:mm') }}</template>
Vue.filter('dateformat', function (dateStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  if (dateStr) {
    return (dateStr === null || dateStr === '') ? '' : moment(dateStr).format(pattern)
  } else {
    return ''
  }
})

// 是否中文显示 {{ scope.row.isPermission | yesNoFormat }}
Vue.filter('yesNoFormat', function (str) {
  let yesNo = ''
  switch (str) {
    case '0': yesNo = '否'
      break
    case '1': yesNo = '是'
      break
  }
  return yesNo
})

// 性别中文显示 {{ scope.row.sex | sexformat }}
Vue.filter('sexFormat', function (str) {
  let sex = ''
  switch (str) {
    case '0': sex = '女'
      break
    case '1': sex = '男'
      break
  }
  return sex
})

// 挂载全局
Vue.prototype.$http = httpRequest // ajax请求方法
Vue.prototype.isAuth = isAuth     // 权限方法
Vue.prototype.moment = moment // moment日期处理控件

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  template: '<App/>',
  render: h => h(App)
})
